# coding=utf-8
import traceback

import pymysql.cursors

from tests.modules.ucloud.servers import servers
from tests.modules.ucloud.ucloud_db import UcloudApp


def deal_all_db(_ip):
    uc = UcloudApp(ip=_ip)

    try:

        uc.do_remove(app_name='add_app_mks.py', zone_alias='gzidc')
        uc.do_remove(app_name='beetle-war-example', zone_alias='gzidc')


        uc.do_insert(app_name='beetle-war-example',
                     zone='uc.gzidc.area',
                     zone_alias='gzidc',
                     port=65480,
                     app_type='tomcat',
                     db_name=None,
                     mem_level=3,
                     db_type=None)

        uc.commit()

    except BaseException, ex:
        print ex.message

    finally:

        uc.close()
servers = [
        "172.16.2.176"
    ]
for _ip in servers:
    try:
        print '准备刷新ucloud%s:' % _ip

        deal_all_db(_ip)

        print 'ucloud%s刷新完成:' % _ip

    except BaseException, ex:
        print ex.message
